﻿using System;
using System.Linq;
using EnvDTE;
using Expect.Core.Fixtures;

namespace Expect.VisualStudio.Extensions.Commands.Handlers
{
    
    class CreateActorFixtureClass : CreateFixtureClass
    {
        public CreateActorFixtureClass(IExpectPackage pkg)
            : base(pkg, CommandIDs.cmdidCreateActorFixtureClass)
        {
        }

        public override string DisplayText
        {
            get
            {
                return "Fixture class => create actor fixture class";
            }
        }

        public override bool ShowCommand(SelectionResolution resolution)
        {
            var res = base.ShowCommand(resolution);
            if (
                res && 
                resolution.IsFixture &&                 
                resolution.Fixture.Rows.Count > 1) return true;

            return false;
        }

        protected override Type GetClassType()
        {
            return typeof(ActorFixture);
        }

        protected override void ProcessClass(SelectionResolution resolution, CodeClass generatedclass)
        {
            for (int i = 1; i < resolution.Fixture.Rows.Count; i++)
            {
                var row = resolution.Fixture.Rows[i];
                var methodname = resolution.NameProvider.ElementName(row.NamesForFluent().ToArray());
                var args = row.ArgsForFluent().ToArray();

                if (!generatedclass.HasMethodWithXArgs(methodname, args.Length))
                {
                    CreateContainerMethod.GetFixtureMethod(resolution, row, methodname, args, generatedclass);
                }
            }
        }
    }
}
